﻿package com.tomvian.maths.areas
{
	import flash.geom.Rectangle;
	import com.tomvian.maths.Vector2D;
	
	/**
	 * RectangleArea
	 * @author Thomas Vian
	 */
	public class RectangleArea extends Area
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		private var _rect:Rectangle;
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function RectangleArea(rect:Rectangle)
		{
			_rect = rect;
			area = _rect.width * _rect.height;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function contains(vector:Vector2D):Boolean 
		{
			return _rect.contains(vector.x, vector.y);
		}
		
		override public function random():Vector2D 
		{
			return new Vector2D(_rect.x + _rect.width * Math.random(), _rect.y + _rect.height * Math.random());
		}
	}
}